#include "timer.h"

#include "ireactor.h"
#include "itimerhandler.h"

#include "env.h"

namespace net {

Timer::Timer() {
    isStart_ = false;
    isPersistent_ = false;
    //net::GetReactor()->AddTimer(this);
}

Timer::~Timer() {
    //net::GetReactor()->AddTimer(this);
}

void Timer::OnTimer() {
    if (handler_) {
        handler_->OnTimer(this);
    }

    if (!isPersistent_) {
        //net::GetReactor()->RemoveTimer(this);
    }
}
    
void Timer::Close() {
    delete this;
}

uint32_t Timer::GetTime() {
    return time_;
}

void Timer::Start(uint32_t time, ITimerHandler* handler, bool isPersistent) {
    if (isStart_) {
        //net::GetReactor()->RemoveTimer(this);
    }

    time_ = time;
    isStart_ = true;
    handler_ = handler;
    isPersistent_ = isPersistent;
    //net::GetReactor()->AddTimer(this);
}

}
